/*
  Copyright (c) 2010 Les Newell. All rights reserved

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "wx_pch.h"
#include "ConfigDialog.h"
#include "wx/ctb/serportx.h"

#ifndef WX_PRECOMP
//(*InternalHeadersPCH(ConfigDialog)
//*)
#endif
//(*InternalHeaders(ConfigDialog)
#include <wx/xrc/xmlres.h>
//*)

//(*IdInit(ConfigDialog)
//*)

BEGIN_EVENT_TABLE(ConfigDialog,wxDialog)
    //(*EventTable(ConfigDialog)
    //*)
END_EVENT_TABLE()

ConfigDialog::ConfigDialog(wxWindow* parent)
{
    //(*Initialize(ConfigDialog)
    wxXmlResource::Get()->LoadObject(this,parent,_T("ConfigDialog"),_T("wxDialog"));
    chPort = (wxChoice*)FindWindow(XRCID("ID_CHOICE1"));
    chBaud = (wxChoice*)FindWindow(XRCID("ID_CHOICE2"));
    //*)
    Connect(XRCID("wxID_OK"),wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ConfigDialog::OnbtnOkClick);

    wxConfigBase * cfg = wxConfigBase::Get();
    cfg->SetPath(_T("/Serial"));
    chPort->SetSelection(cfg->Read(_T("Port"),1l));
    chBaud->SetSelection(cfg->Read(_T("Baud"),10l));
}

ConfigDialog::~ConfigDialog()
{
    //(*Destroy(ConfigDialog)
    //*)
}


void ConfigDialog::OnbtnOkClick(wxCommandEvent& event)
{
    wxConfigBase * cfg = wxConfigBase::Get();
    cfg->SetPath(_T("/Serial"));
    cfg->Write(_T("Port"),chPort->GetSelection());
    cfg->Write(_T("Baud"),chBaud->GetSelection());
    event.Skip();
}
